home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / 80X86 / ASMFAQ.ZIP / ASM_FAQ1.TXT next >
Encoding:
Internet Message Format  |  1996-04-03  |  30.2 KB

  1. From news.primenet.com!nntp.news.primenet.com!news.sprintlink.net!gryphon.phoenix.net!academ!binky.capnet.state.tx.us!goblin.tdh.state.tx.us!geraldo.cc.utexas.edu!cs.utexas.edu!howland.reston.ans.net!swrinde!sgigate.sgi.com!news1.best.com!news.aimnet.com!ns2.mainstreet.net!sloth.swcp.com!news.dgsys.com!DGS.dgsys.com!raymoon Tue Apr  2 15:44:59 1996
  2. Path: news.primenet.com!nntp.news.primenet.com!news.sprintlink.net!gryphon.phoenix.net!academ!binky.capnet.state.tx.us!goblin.tdh.state.tx.us!geraldo.cc.utexas.edu!cs.utexas.edu!howland.reston.ans.net!swrinde!sgigate.sgi.com!news1.best.com!news.aimnet.com!ns2.mainstreet.net!sloth.swcp.com!news.dgsys.com!DGS.dgsys.com!raymoon
  3. From: raymoon@dgsys.com (Raymond Moon)
  4. Newsgroups: alt.lang.asm,comp.lang.asm.x86,news.answers,alt.answers,comp.answers
  5. Subject: x86 Assembly Language FAQ - General Part 1/3
  6. Supersedes: <4gdsi8$o9c@news.dgsys.com>
  7. Followup-To: alt.lang.asm,comp.lang.asm.x86
  8. Date: 21 Mar 1996 22:48:59 GMT
  9. Organization: MoonWare
  10. Lines: 760
  11. Approved: news-answers-request@MIT.EDU
  12. Distribution: world
  13. Expires: Sat, 20 Apr 1996 23:59:59 GMT
  14. Message-ID: <4ismcr$2tq@news.dgsys.com>
  15. Reply-To: raymoon@moonware.dgsys.com
  16. NNTP-Posting-Host: dgs.dgsys.com
  17. Summary: This is the FAQ for the x86 Assembly Language programmers for the
  18.  alt.lang.asm and comp.lang.asm.x86 newsgroups.  This particular section of
  19.  the FAQ is part one of three parts that contain x86 assembly language
  20.  information common to all assemblers.
  21. Keywords: x86 Assemby Language ASM FAQ General
  22. X-Newsreader: TIN [version 1.2 PL2]
  23. Xref: news.primenet.com alt.lang.asm:8420 comp.lang.asm.x86:18597 news.answers:66830 alt.answers:16272 comp.answers:17529
  24.  
  25. Archive-name: assembly-language/x86/general/part1
  26. Posting-Frequency: monthly (21st of every month)
  27. Last-modified: 1996/03/19
  28.  
  29. ------------------------------
  30.  
  31. Subject: 1. Introduction and Intent
  32.  
  33. This is the x86 Assembly Language FAQ for the comp.lang.asm.x86 and
  34. alt.lang.asm newsgroups.  This FAQ is posted monthly on or about the 21st
  35. of the month on both newsgroups and news.answers, alt.answers and
  36. comp.answers.  It also is archived at the normal FAQ archival sites and the
  37. SimTel mirror sites in the msdos/info directory.  Lastly, the current
  38. version is available from my web page as:
  39.     http://www2.dgsys.com/~raymoon/faq/asmfaq.zip
  40. Currently, this FAQ is broken into six sections.  The following are the
  41. section filenames and the scope of each section of the FAQ.
  42.  
  43. assembly-language/x86/general/part1 - This is the basic portion of the FAQ
  44.     that contains information of interest to all assembly language
  45.     programmers.  In general, the information contained in this portion of
  46.     the FAQ is not specific to any particular assembler.
  47.  
  48. assembly-language/x86/general/part2 - This is a continuation of the above
  49.     FAQ.
  50.  
  51. assembly-language/x86/general/part3 - This is a continuation of the above
  52.     FAQ.
  53.  
  54. assembly-language/x86/microsoft - This portion of the FAQ contains
  55.     information specific for the Microsoft MASM.
  56.  
  57. assembly-language/x86/borland - This portion of the FAQ contains
  58.     information specific for the Borland TASM.
  59.  
  60. assembly-language/x86/a86 - This portion of the FAQ contains information
  61.     specific for the Shareware A86 Assembler and D86 Debugger.
  62.  
  63. The scope and content of this FAQ is to go beyond just answering the
  64. frequently asked questions.  I am including pointers to assembly language
  65. treasure troves that are hidden out on the internet.  I believe that this
  66. will enhance the FAQ's value not only to the novices but also to the old
  67. hands.
  68.  
  69. Any subject listed as "OPEN" means that this topic as been requested but no
  70. one has come forth and volunteered to write this section.  Volunteers
  71. please indicate your intentions to the author listed below either by
  72. posting to either newsgroup or by sending e-mail to the author at the below
  73. address.
  74.  
  75. The general guidelines for submission are:
  76.  *  accuracy and conciseness;
  77.  *  pointers to where on the internet more detailed information is
  78.     available; and
  79.  *  any code submitted will be generic so that most assemblers can assemble
  80.     successfully.
  81.  
  82. Any subject listed as "UNDER CONSTRUCTION" has a volunteer currently
  83. writing that subject.  If you desire to assist or have some information
  84. that you believe would be of help in writing that particular subject,
  85. contact the contributor of that subject or post to both newsgroups.  Once a
  86. subject is submitted to me, I will post it on both newsgroups for comment. 
  87. After any changes that may be necessary are made, I will include it in the
  88. next posting of the FAQ.
  89.  
  90. For the ease of determining what has changed since the last FAQ, the Table
  91. of Contents will have "REVISED" at the end of the subject line for all
  92. revised subjects.  If more than one FAQ revision has been missed, the "Last
  93. Changed:" entry at the end of each subject can be used to determine which
  94. subjects have been revised during the intervening time frame.
  95.  
  96. The information in this FAQ is free for all to use as long as you
  97. acknowledge the source.  This FAQ can be reproduced in part or in its
  98. entirety as long as the copyright is included.  This FAQ can be made
  99. available on public servers, like ftp, gopher or WWW servers.  Please do
  100. not modify the file, such as converting it into some other format, without
  101. prior permission of the author.
  102.  
  103. All references to files and locations are in Uniform Resource Locators
  104. (URLs) format.  Some web browser will be able to use these URLs directly as
  105. hot links.  If the format is not clear to you, get RFC 1738.  It is
  106. available from:   ftp://is.internic.net/rfc/rfc1738.txt 
  107.  
  108. Suggestions for changes and comments are always welcome.  They can be
  109. posted to either newsgroup or e-mailed directly to the me.
  110.  
  111. Author: Raymond Moon, raymoon@moonware.dgsys.com
  112. Copyright 1996 - Raymond Moon
  113. ALL RIGHTS RESERVED
  114. Last Changed: 17 Feb 96
  115.  
  116. ------------------------------
  117.  
  118. Subject: 2. Table of Contents
  119.  
  120. Part I
  121.  
  122. 1.  Introduction and Intent
  123. 2.  Table of Contents                                   REVISED
  124. 3.  Charters For comp.lang.asm.x86 and alt.lang.asm Newsgroups
  125. 4.  What is Assembly Language
  126. 5.  List of x86 OpCodes
  127. 6.  What is HELPPC and Where It Is Available
  128. 7.  How To Truncate a File
  129. 8.  How Can STDERR Be Redirected To a File
  130. 9.  How To Determine the CPU Type
  131. 10. IRQ Assignments
  132. 11. Ralf Brown's Interrupt List
  133. 12. Using VGA Mode 13h for Fast Graphics
  134. 13. Real Mode/Protected Mode
  135. 14. Shareware ASM Libraries
  136.  
  137. Part II
  138.  
  139. 15. How To Determine If a Problem Pentium Is Present
  140. 16. Accessing 4 Gegs of Memory in Real Mode
  141. 17. Interrupts and Exceptions
  142. 18. What Is Available at ftp.intel.com
  143. 19. ASM Books Available
  144. 20. ASM Code Available on Internet
  145. 21. How To Commit a File
  146. 22. Using Extended Memory Manager
  147. 23. EXE2BIN Replacement
  148. 24. ASM Tutorials Available
  149.  
  150. Part III
  151.  
  152. 25. Shareware Assemblers                                REVISED
  153. 26. WWW Assembly HomePages                              REVISED
  154. 27. Undocumented OpCodes
  155. 28. Common Reason Why Memory Allocation Fails
  156. 29. Volume Serial Numbers
  157. 30. .obj File Format
  158. 31. Rebooting from Software
  159. 32. Other FAQs
  160. 33. Acknowledgments
  161.  
  162. ------------------------------
  163.  
  164. Subject: 3. Charters For comp.lang.asm.x86 and alt.lang.asm Newsgroups
  165.  
  166. To know whether or not these newsgroups will meet your needs, the purpose
  167. for which they were created are given below.
  168.  
  169. 3.1  COMP.LANG.ASM.X86
  170.  
  171. comp.lang.asm.x86 was created based upon voting on a Request for Discussion
  172. (RFD).  The RFD for this newsgroup is:
  173.  
  174. The unmoderated newsgroup comp.lang.asm.x86 is open to discussions on all
  175. topics related to assembly language and low-level programming on IBM
  176. machines with '86 processors.  Appropriate topics would include, but not be
  177. limited to:
  178.  
  179.     Assembly language tips and tricks (code techniques)
  180.     MASM, TASM, and other commercial assemblers
  181.     Graphics, sound, and other hardware programming
  182.     Assembly language code
  183.     Assembly language related share/freeware
  184.     Linking assembly language with other languages
  185.     Etc...
  186.  
  187. Topics that are discouraged are:
  188.  
  189.     Flames about "{Language X} is {better/worse} than ASM"
  190.     Flames like "{Assembler 1} is {better/worse} than {Assembler 2}"
  191.     High-level language code, except when used for hardware programming
  192.  
  193. 3.2  ALT.LANG.ASM
  194.  
  195. Alt newsgroups are initiated with a Proposal posting to the alt.config
  196. newsgroup.  The proposal for alt.lang.asm is:
  197.  
  198. alt.lang.asm will address the problems of machine language programmers out
  199. there in InterNet land.  It will be a forum for discussion of coding
  200. techniques and efficiency problems related to machine language.  The scope
  201. will be broad.  We will not discriminate by machine architecture, race or
  202. sex.
  203.  
  204. Contributors: Michael Averbuch, mikeaver@firefly.prairienet.org
  205.               Raymond Moon, raymoon@moonware.dgsys.com
  206. Last changed: 28 Dec 94 
  207.  
  208. ------------------------------
  209.  
  210. Subject: 4. What Is Assembly Language
  211.  
  212. 4.1  WHAT IS MACHINE LANGUAGE?
  213.  
  214. Although programmers tend to use C or C++ or Pascal these days, the
  215. language closest to the PC hardware is machine language.  Not one second
  216. during a PC's powered on lifetime passes where the computer is not
  217. executing machine language.
  218.  
  219. 4.2  ASSEMBLY LANGUAGE OR MACHINE LANGUAGE
  220.  
  221. To word this simply, you can say that say that assembly language is a
  222. human-readable text, and machine language is machine-readable binary code.
  223. When you program in assembly language, you are programming on the machine
  224. language level.
  225.  
  226. To program directly in machine language is teadious, so you use assembly
  227. language instead, and use an assembler to produce the actual machine code.
  228.  
  229. 4.3  WHEN TO USE ASSEMBLY LANGUAGE
  230.  
  231. I personally think that except as a learning exercise it's a waste of time
  232. writing something in asm that can be written acceptably fast in a
  233. high-level language.
  234.  
  235. Assembly language fits for the following:
  236.  
  237.  *  Low level control.  When you need to change the flags, or the control
  238.     registers of the processor, as when entering protected mode.
  239.  
  240.  *  Speed.  Programs written in machine language execute fast!  It can
  241.     execute 10-100 times the speed of BASIC, and about twice as fast as a
  242.     program written in C or Pascal.
  243.  
  244.  *  Time Critical Code.  Critical sections of programs written in higher
  245.     level languages, can be written in assembly to speed up sections.
  246.  
  247.  *  Small program size.  When you write a TSR for example this is very
  248.     useful. Writing interrupt handlers is where assembly language shines.
  249.  
  250. Assembly language is very flexible and powerful, anything that the hardware
  251. of the computer is capable of doing can be done in assembly.
  252.  
  253. Contributor: Patrik Ohman, patrik@astrakan.hgs.se
  254. Last changed: 10 Jan 95
  255.  
  256. ------------------------------
  257.  
  258. Subject: 5. List Of x86 OpCodes
  259.  
  260. To obtain a full listing of the instruction set, opcodes and instruction
  261. timing of the Intel processors, the book
  262.  
  263. Pentium<tm> Family, User's Manual
  264. Volume 3: Architecture and Programming Manual
  265. ISBN 1-55512-227-12
  266.  
  267. is the best source of information.
  268.  
  269. This book is available directly from Intel by calling or writing: 
  270. Intel Literature Sales
  271. P.O. Box 7641
  272. Mt. Prospect, IL 60056-7641
  273. (800) 548-4725
  274.  
  275. Another source of information on the instruction set is the program HelpPC,
  276. see obtaining HELPPC elsewhere in this document.
  277.  
  278. Contributor: Patrik Ohman, patrik@astrakan.hgs.se
  279. Last changed: 10 Jan 95
  280.  
  281. ------------------------------
  282.  
  283. Subject: 6. What Is HELPPC and Where Is It Available
  284.  
  285. HELPPC is a Quick Reference Utility for the intermediate to advanced
  286. programmer.  It is a shareware program written by David Jurgens.  The
  287. latest version is 2.10
  288.  
  289. The topics distributed in an easy database format are:
  290.     BIOS interrupts;
  291.     DOS interrupts and DOS functions;
  292.     EMS and Mouse functions;
  293.     BIOS and DOS data structures;
  294.     diagnostic codes;
  295.     DOS commands;
  296.     80x86 assembler instructions;
  297.     standard and vendor specific C functions; and
  298.     various hardware specifications.
  299.  
  300. HELPPC is customizable by users.  The documentation describes how users can
  301. incorporate their own information into the help file format.  These user
  302. help files then can be incorporated into the database and accessed via
  303. HELPPC application.
  304.  
  305. HELPPC comes in two versions.  The first is a DOS command line program. 
  306. The second is a TSR.  The TSR supports context sensitive help within many
  307. editors.  Only 32K is taken by the TSR version.
  308.  
  309. HELPPC requires:
  310.     DOS 2.0 or greater;
  311.     64K of RAM for DOS Command Line or 32K for TSR; and
  312.     hard disk recommended.
  313.  
  314. HELPPC is available specifically from:
  315.  
  316.     ftp://ftp.coast.net/SimTel/msdos/info/helppc21.zip
  317.  
  318. HELPPC also is available from any site that mirrors the SimTel directory.
  319.  
  320. Contributor:  Raymond Moon, raymoon@moonware.dgsys.com
  321. Last changed: 28 Dec 94
  322.  
  323. ------------------------------
  324.  
  325. Subject: 7. How To Truncate A File
  326.  
  327. There is not any single DOS Int 21h function that performs this operation. 
  328. A file can be truncated using two functions.  The procedure is:
  329.  
  330. 1.  Use Int 21h function 42h, Move File Pointer, to move the file pointer
  331.     to the position where you want the file to be truncated.
  332. 2.  Use Int 21h function 40h, Write File or Device, to write zero bytes to
  333.     the file.
  334.  
  335. Execution of the last DOS function will update the directory to the new
  336. file length.
  337.  
  338. Contributor: Raymond Moon, raymoon@moonware.dgsys.com
  339. Last changed: 28 Dec 94
  340.  
  341. ------------------------------
  342.  
  343. Subject: 8. How Can STDERR Be Redirected To A File
  344.  
  345. I understand that 4DOS has this capability at its command line.  If you are
  346. looking in the assembly language FAQ for this information, an assembly
  347. language answer probably is desired.  Here it is.
  348.  
  349. You will need to write a short program that performs the STDERR redirection
  350. before loading and executing the desired program.  This loader program
  351. relies upon the fact that a child program inherits all open files of the
  352. parent program unless the parent program opens a file with the inheritance
  353. flag set to no.
  354.  
  355. Because the full code for such a program is too large for this FAQ, I will
  356. give are the salient specifications for such a program.
  357.  
  358. 1.  The loader program accepts three command line arguments:
  359.     a.  The full path and filename of the file into which STDERR is to be
  360.         written.
  361.     b.  The full path and filename of the program to be executed.
  362.     c.  The command line for the program to be executed (should be
  363.         delimited by double quotes to allow multiple arguments).  This
  364.         argument is optional.
  365. 2.  Release all memory above the program using Int 21 function 4ah so that
  366.     there will be room enough to load and execute the designated program. 
  367. 3.  Open the file from step 1.a above into which STDERR is to be written.
  368. 4.  Duplicate STDERR filehandle, which is 2, using Int 21h function 45h.
  369. 5.  Using Int 21h function 46h, force STDERR filehandle, again 2, to have
  370.     the filehandle of the opened file from step 2.
  371. 6.  Use Int 21h function 4b00h to load and execute the program from step
  372.     1.a.  Use the default environment and the command line from step 1.c
  373.     above.
  374. 7.  Upon return from the function 4b00h, close the file opened in step 2.
  375. 8.  To restore STDERR, use Int 21h function 46h to force STDERR, again 2,
  376.     to point to the filehandle saved from step 3 above.
  377.  
  378. This same technique can be applied to any of the standard devices.
  379.  
  380. I have written a full featured demonstration program.  I believe that asm
  381. programmers will find the source code useful even if they do not want to
  382. redirect stderr to a file.  The URL to the file is:
  383.  
  384.     ftp://ftp.coast.net/SimTel/msdos/asmutil/stderrf.zip
  385.  
  386. Contributor: Raymond Moon, raymoon@moonware.dgsys.com
  387. Last changed: 3 Jun 95
  388.  
  389. ------------------------------
  390.  
  391. Subject: 9. How To Determine The CPU Type
  392.  
  393. 9.1  CPUID PROGRAM
  394.  
  395. The type of processor and math coprocessor can be determined using two
  396. functions that have been provided by Intel.  The source code to these
  397. functions can be obtained from Intel by:
  398.  
  399.  
  400.     ftp://ftp.intel.com/pub/IAL/tools_utils_demos/cpuid3.zip
  401.  
  402. Three source files are included in this .zip file.
  403.     cpuid3a.asm - This source code file contains two assembly language
  404.         functions.  One determines the type of cpu from 8088/8086 to
  405.         Pentium.  The second detects and identifies, if present, the type
  406.         of math coprocessor.
  407.     cpuid3b.c - a c program that calls the above two functions and displays
  408.         the results.
  409.     cpuid3c.asm - this is an assembly program equivalent to cpuid3b.c.
  410.  
  411. 9.2  CPUID INSTRUCTION
  412.  
  413. On some 486 and all Pentium processors, Intel has included an undocumented
  414. CPUID instruction.  More information on this instruction and how to tell if
  415. a processor supports this instruction, see Ralf Brown's OPCODE.LST, Subject
  416. #11).
  417.  
  418. You also can get the word directly from Intel
  419.  
  420.     ftp://ftp.intel.com/pub/IAL/Software_specs/cpuap.zip
  421.  
  422.     The file in the .zip file describes the CPUID instruction, explains the
  423. evolution of CPU detections strategies and includes the source code for the
  424. CPUID program.  UNFORTUNATELY, the format for the file is a postscript
  425. print file.  To get a human readable copy, it must be sent to a postscript
  426. viewer or printer!
  427.  
  428. 9.3  Robert Collins' CPUID.ASM
  429.  
  430. Robert Collins has posted a his version of cpuid which will detect the P6
  431. or Pentium Pro.  To date, checking the above Intel site, I could not find
  432. an updated Intel routine.
  433.  
  434.     ftp://ftp.x86.org/x86/source/CPUID/CPUID.ASM
  435.  
  436. Contributor: Raymond Moon, raymoon@moonware.dgsys.com
  437. Last changed: 11 Nov 95  
  438.  
  439. ------------------------------
  440.  
  441. Subject: 10. IRQ Assignments
  442.  
  443. A list of IRQ assignments are available in David Jurgens' HELPPC database. 
  444. See Subject #6 for details on how to obtain this program.
  445.  
  446. Contributor: Raymond Moon, raymoon@moonware.dgsys.com
  447. Last changed: 28 Dec 94  
  448.  
  449. ------------------------------
  450.  
  451. Subject: 11. Ralf Brown's Interrupt List
  452.  
  453. 11.1  FILE AVAILABILITY
  454.  
  455. The latest version of Ralf Brown's Interrupt List is 4.9.  The files are
  456. available directly from his home page, from SimTel, or Garbo:
  457.  
  458.     http://www.cs.cmu.edu/afs/cs.cmu.edu/ralf/pub/WWW/files.html
  459.     ftp://ftp.coast.net/SimTel/msdos/info
  460.     ftp://garbo.uwasa.fi/pc/programming
  461.  
  462. The files are:
  463. inter48a.zip    Comprehensive listing of interrupt calls, 1 of 4
  464. inter48b.zip    Comprehensive listing of interrupt calls, 2 of 4
  465. inter48c.zip    Comprehensive listing of interrupt calls, 3 of 4
  466. inter48d.zip    Comprehensive listing of interrupt calls, 4 of 4
  467. inter48e.zip    Hypertext/utility programs for interrupt list
  468. inter48f.zip    WinHelp conversion programs for interrupt list
  469. inter48z.zip    HC31/HCP phrases file for interrupt list
  470. intwin48.zip    WINHELP hypertext 
  471.  
  472. 11.2  DESCRIPTION
  473.  
  474. This interrupt list is an extensive listing of functions available through
  475. interrupt and FAR calls.  Both documented and undocumented calls are
  476. included.  Also available are maps of CMOS and BIOS memory and I/O ports. 
  477. The current release contains 7,800 entries and over 3,100 tables.
  478.  
  479. 11.3  WHAT IS NEW
  480.  
  481. Version 4.7:
  482. HP 100LX/200LX calls, some Windows95, XMZ, LAN Manager data structures,
  483. Linux DOSEMU, NetWare printing and VLMs, HugeRealMode Server, GO! Directory
  484. locator, XDF.  Plus, a significantly expanded PORTS.LST and a reformatted
  485. MEMORY.LST
  486.  
  487. Version 4.8:
  488. 380K of new information (400 new calls), including Pentium Local APIC,
  489. ATA-2/ATA-3 IDE specs, Bootable CD-ROM specification, Enhanced Disk Drive
  490. Spec v1.1, PCI BIOS v2.1, EPP BIOS v7, Multiprocessor Specification, Smart
  491. Battery protocol, additional Plug-and Play info, Atari Portfolio, HP Hornet
  492. chipset, MODAL PC, K3PLUS updates, WinDOS, many additional NetWare
  493. functions, many additional I/O ports.  Updated OPCODES.LST, new file
  494. TABLES.LST containing pointers to selected tables, new list viewer IVIEW.
  495.  
  496. Version 4.9:
  497. Zfax v4, BSC/SDLC ports, Q87 v4, I1541, CauseWay v1.3 DOS extender,
  498. additional I/O ports, and updated OPCODES.LST.
  499.  
  500. 11.4  VIEWERS
  501.  
  502. Ralf Brown has included quite a few viewers.  They are included as embedded
  503. .zip files.  I would unzip them into separate files and determine which one
  504. best fits your needs.
  505.  
  506. 11.5 OTHER INCLUDED GEMS
  507.  
  508. OVERVIEW.LST - A brief description of each of the 256 interrupts.
  509. 86BUGS.LST - A list of undocumented and buggy instructions with
  510.     descriptions of the x86 Intel processor and compatible processors.  And
  511.     you thought that the Intel FDIV was the first bug in a processor!
  512. CMOS.LST - a CMOS memory map.
  513. OPCODE.LST - A list of undocumented instructions and documented
  514.     instructions of any last processor.
  515. PORTS.LST - I/O port addressed for XT, AT and PS/2 computers.
  516. GLOSSARY.LST - glossary of PC terms.
  517. MEMORY.LST - The format for various memory locations, such as the BIOS Data
  518.     Segment, Interrupt Vector Table, and much, much more.
  519. INTERRUP.PRI - iAPX 86 Interrupt Primer
  520.  
  521. Contributor: Raymond Moon, raymoon@moonware.dgsys.com
  522. Last changed: 17 Feb 96 
  523.  
  524. ------------------------------
  525.  
  526. Subject: 12. Using VGA Mode 13h for Fast Graphics
  527.  
  528. 12.1  INTRODUCTION AND PREPARATION
  529.  
  530. Mode 13h is so widely used for graphics applications in DOS because it is
  531. very easy to use.  The screen is constantly being redrawn by the video
  532. card.  To affect what the card draws, it is necessary to write to the
  533. screen buffer.  The screen buffer in mode 13h is always at segment:offset =
  534. A000:0000.  Thus, to set up drawing directly to the video buffer, this is
  535. what you'd most often first do:
  536.  
  537.   ;Change the video mode to 13h
  538.     xor  ah, ah         ;VIDEO Function 00h: Change screen
  539.     mov  al, 13h        ;Put the desired graphics mode into AL
  540.     int  10h            ;Call VIDEO
  541.  
  542.   ;Prepare for writing to the video buffer
  543.     mov  di, 0a000h     ;Put the video segment into DI
  544.     mov  es, di         ; so it can easily be put into ES
  545.     xor  di, di         ;Start writing at coordinates (0,0)
  546.  
  547. 12.2  WRITING PIXELS TO THE SCREEN
  548.  
  549. Why is Mode 13h so popular?  To understand, you must know a few basic
  550. facts.  In Mode 13h, the screen is 320 by 200, or 320 pixels across and 200
  551. pixels down.  In each pixel, there's a possibility of 256 colors, which can
  552. be fit into one byte.  Thus, 320*200*1 = 64000 bytes, about the size of one
  553. segment.  Think of the screen as an array of colors.  The first row takes
  554. up addresses A000:0000 to A000:013F (decimal 319), the second row takes up
  555. addresses A000:0140 to A000:027F (decimal 639), and so on.  To plot a
  556. pixel, assuming ES=A000:
  557.  
  558.   ;Plot a pixel in video mode 13h, where
  559.   ;PixelAddress = (320 * Y) + X
  560.     mov  ax, 320        ; Prepare for the multiplication  
  561.     mul  [Y]            ; Assuming that Y is defined in the data segment
  562.                         ;   earlier in the program
  563.     mov  di, ax         ; Put in into the pointer to the offset of ES
  564.     add  di, [X]        ; Assuming that X is defined in the data segment
  565.                         ;   earlier in the program
  566.     mov  al, [Color]    ; Assuming that Color is defined in the data
  567.                         ;   segment earlier in the program
  568.     stosb               ; Write it to the screen!
  569.  
  570. See how easy that was?  Something to remember is that it is zero-based. 
  571. The upper-left corner is (0,0), and the lower-right is (319,199).  A
  572. complete TASM Ideal mode procedure might look something like this (it
  573. assumes that the video card is already set to mode 13h):
  574.  
  575. PROC WritePixel BASIC   ; Or whatever language you might want to link
  576.                         ;  it to
  577.     USES es, di         ; It's always a good idea to preserve ES and DI
  578.     ARG  X:word, Y:word, Color:BYTE
  579.     mov  di, 0a000h     ; Put the video segment into DI
  580.     mov  es, di         ;   so it can easily be put into ES
  581.     mov  ax, 320        ; Prepare for the multiplication
  582.     mul  [Y]            ; Offset pointer by the Y value passed in
  583.     mov  di, ax         ; Put in into pointer to the offset of ES
  584.     add  di, [X]        ; Offset the pointer by the X value passed in
  585.     mov  al, [Color]    ; Put color to be written to the screen in AL
  586.     stosb               ; Write it to the screen!
  587.     ret
  588. ENDP WritePixel
  589.  
  590. To write a horizontal line, just put the length in CX, and replace the
  591. STOSB with a REP STOSB.  Writing a vertical line is only a little more
  592. tricky.  Observe the following TASM Ideal mode procedure:
  593.  
  594. PROC VerticalLine BASIC ; Or whatever language you might want to link
  595.                         ;  it to
  596.     USES es, di         ; It's always a good idea to preserve ES and
  597.                         ;  DI
  598.     ARG  X:word, Y:word, Color:BYTE, Length:word
  599.     mov  di, 0a000h     ; Put the video segment into DI
  600.     mov  es, di         ; so it can easily be put into ES
  601.     mov  ax, 320        ; Prepare for the multiplication  
  602.     mul  [Y]            ; Offset the pointer by the Y value passed in
  603.     mov  di, ax         ; Put in into the pointer to the offset of ES
  604.     add  di, [X]        ; Offset the pointer by the X value passed in
  605.     mov  al, [Color]    ; Put the color to be written to the screen
  606.                         ; in AL
  607.     mov  cx, [Length]   ; Prepare for the loop
  608. YLoop:
  609.     stosb               ; Write it to the screen!
  610.     add  di, 319        ; Move down one row (DI has already advanced
  611.                         ;  once because of the STOSB, thus the 319)
  612.     loop YLoop
  613.     ret
  614. ENDP VerticleLine
  615.  
  616. Observe how there is a tight loop that moves DI down one row each
  617. iteration.
  618.  
  619. In short, the easiest way to write directly to the Mode 13h video buffer is
  620. to think of the screen as just a 320 by 200 array of bytes, starting at
  621. A000:0000.
  622.  
  623. Author: Michael Averbuch (mikeaver@prairienet.org)
  624. Last Change: 29 Dec 94
  625.  
  626. ------------------------------
  627.  
  628. Subject: 13. Real Mode/Protected Mode
  629.  
  630. 13.1  AVAILABILITY
  631.  
  632. [Note:  because of a crash at zfja-gate, the below information of files on
  633. zfja-gate may not be accurate.]
  634.  
  635. All the files below are available from:
  636.     ftp://zfja-gate.fuw.edu.pl/user/net/ka9q/guest/cpu/protect.mod
  637.  
  638. The authors e-mail addresses are given below.
  639.  
  640. These files can be received by e-mail.  Send e-mail to:
  641.  
  642.     listserv@zfja-gate.fuw.edu.pl
  643.  
  644. with GET CPU/PROTECT.MOD/PMFAQ/* in the text.
  645.  
  646. A .zip file with all the latest files described below has been uploaded to
  647. SimTel but as of 19 Dec has not been made available for download.  The URL
  648. to this file when available should be:
  649.  
  650.     ftp://ftp.coast.net/SimTel/msdos/info/pmtut0002.zip 
  651.  
  652. Watch this site or for the upload announcement in the newsgroups.
  653.  
  654. 13.2  FAQ - PMFAQ.ZIP
  655.  
  656. This file contains a preliminary protected mode FAQ by Jerzy Tarasiuk.
  657.  
  658. 13.3  TUTORIAL - PMTUT002.ZIP
  659.  
  660. Till Gerken has written a Protected Mode Tutorial.  This tutorial contains
  661. code and applicable function calls that comprise the Virtual Control
  662. Program Interface (VCPI).  Till Gerken's tutorial is available:
  663.  
  664.     ftp://x2ftp.oulu.fi/pub/msdos/programming/pmode/pmtut002.zip
  665.  
  666. 13.4  SAMPLE ASM CODE - SIMPL_PM.ASM
  667.  
  668. Jerzy Tarasiuk has posted an example program switching to Protected Mode
  669. and back to again to Real Mode.
  670.  
  671. 13.5 REAL MODE IDT SWITCHING - CHANGIDT.FAQ
  672.  
  673. Lastly Jerzy Tarasiuk has included some of his e-mail that covers real mode
  674. IDT switching.
  675.  
  676. Contributors: Till Gerken <tig@ngo.ol.ni.schule.de> and 
  677.               Jerzy Tarasiuk <JT@zfja-gate.fuw.edu.pl>
  678. Last changed: 19 Dec 95
  679.  
  680. ------------------------------
  681.  
  682. Subject: 14. Shareware ASM Libraries
  683.  
  684. 14.1  ASMLIB PROGRAMMER'S TOOLKIT, VERSION 3.7
  685.  
  686. Douglas Herr's shareware assembly language library.  This library is
  687. available from SimTel.
  688.  
  689.     ftp://ftp.coast.net/SimTel/msdos/asmutil/asmlib37.zip
  690.  
  691. The zip file contains only the medium model of the library.  There are 405
  692. assembly subroutines in a .lib file and documentation.  Source code is
  693. available with registration and extra fee.  The library covers the
  694. following areas:
  695.     string/integer data manipulation
  696.     disk & file subroutines
  697.     EMS and XMS subroutines
  698.     floating-point subroutines
  699.     graphics
  700.     keyboard input subroutines
  701.     screen mode subroutines
  702.     text-mode multi-window subroutines
  703.     mathematical solutions
  704.     subroutines which determine PC status
  705.     text-mode video subroutines
  706.  
  707. asmlib37 also comes with an editor, E16, written entire with asmlib.
  708.  
  709. 14.2  THE ASSEMBLY WIZARD'S LIBRARY, VERSION 1.6
  710.  
  711. This is Thomas Hanlin's shareware assembly language library.  This library
  712. is available from SimTel.
  713.  
  714.     ftp://ftp.coast.net/SimTel/msdos/asmutil/asmwiz16.zip 
  715.  
  716. This library comes with documentation and one .lib file that supports small
  717. and tiny memory models.  Source code is available with registration. The
  718. library covers the following areas:
  719.  
  720.     Base Conversions        Mouse Services
  721.     Exception Handling      Sound and Music
  722.     Delays and Countdowns   String Services
  723.     File Handling           Telecommunications
  724.     Filename Manipulation   Time and Date
  725.     Keyboard Services       Video Services
  726.     Long Integer Math       Miscellaneous Services
  727.     Memory Services
  728.  
  729. 14.3  UCR Standard Library for Assembly Language Programmers
  730.  
  731. This library is written by Randall Hyde and others.  This library is
  732. available from SimTel.
  733.  
  734.     ftp://ftp.coast.net/SimTel/msdos/asmutil/stdlib.zip
  735.  
  736. Unlike the previous libraries, there is no registrations fees and the
  737. included source code is released to the public domain.  The author does
  738. request that if you use the library, you contribute at least one routine to
  739. the library.
  740.  
  741.     Standard Input Routines     Character Set Routines
  742.     Standard Output Routines    Memory Management Routines
  743.     Conversion Routines         String Handling Routines
  744.     Utility Routines
  745.  
  746. 14.4  ALIB Version 3.0
  747.  
  748. ALIB is Jeff Ownens' shareware assembly language library.  This library is
  749. available from SimTel.
  750.  
  751.     ftp://ftp.coast.net/SimTel/msdos/asmutil/alib30.zip
  752.  
  753. Like the UCR library described above, registration fees are not requested. 
  754. The library consists of 179 assembly source files covering the following
  755. areas:
  756.  
  757.     compress    - data compression and expansion
  758.     config      - program configuration, colors, paths, etc.
  759.     compare     - compare strings
  760.     convert     - hex/decimal/ascii conversions
  761.     database    - simple database functions
  762.     disk        - disk information, path changes, file searches
  763.     display     - fast display functions, write to display memory
  764.     error       - error handlers
  765.     float       - simple floating point math package
  766.     math        - dword math, crc, roots
  767.     memory      - memory manager, extended, xms, ems, conventional
  768.     menu        - menuing system
  769.     message     - messages in windows on screen
  770.     misc        - misc routines
  771.     mouse/key   - mouse and keyboard functions
  772.     parse       - extraction of parameters from command line
  773.     random      - random number generators
  774.     search      - search for character or string
  775.     sort        - sort buffer or file
  776.     sound       - sounds 
  777.     string      - ascii string handling
  778.     stdout      - characters, strings, spaces to stdout
  779.     system      - system interrogation and setup
  780.     time        - time and date conversions
  781.  
  782. Contributor: Raymond Moon, raymoon@moonware.dgsys.com
  783. Last changed: 1 Jan 95
  784.  
  785.  
  786.